layui.use(['form','table','jquery','layer'],function () {
    var $ = layui.jquery;
    var form = layui.form;
    var table = layui.table;
    var layer = layui.layer;

    select("");
    function select(feedbackType) {
        table.render({
            elem:"#root",
            url:"/Feedback/selectAdoptUserFeedBack?feedbackType="+feedbackType,
            toolbar:"#lefttool",
            limit: 5,
            limit: [5,10,15],
            page: {
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                first: "首页",
                last: "尾页",
            },
            size: 'lg',
            cols:[[
                {type:'checkbox',align:"center"},
                {field:"feedbackId",title:"编号",align:"center"},
                {field:"feedbackType",title:"反馈类型",align:"center",templet:function (data) {
                        if(data.feedbackType==2){
                            return "视频反馈";
                        }else if(data.feedbackType==3){
                            return "商品反馈";
                        }else{
                            return "其他反馈";
                        }
                    }},
                {field:"feedbackContent",title:"反馈内容",align:"center"},
                {field:"feedbackStatus",title:"审核状态",align:'center',height:50,templet:function (data) {
                        if(data.feedbackStatus==2){
                            return '已提交';
                        }else if(data.feedbackStatus==3){
                            return "待审核";
                        }else if(data.feedbackStatus==4){
                            return "审核通过";
                        }else if(data.feedbackStatus==5){
                            return "未提交";
                        }else{
                            return "审核驳回";
                        }
                    }},
                {title:"操作",align:"center",templet:function (data) {
                        return "<div>"+
                            "<a href='javascript:chakan("+data.feedbackId+");'style='color: #0EAA9E;margin-right: 10px'>查看</a>"
                            +"<a href='javascript:shanchu("+data.feedbackId+");' style='color: #0EAA9E;'>删除</a>"
                            +"</div>"
                    }}
            ]]
        })
    };
    //搜索
    $("#sousuo").click(function () {
        var feedbackType = $("#feedbackType").val();
        if(feedbackType=="视频反馈"){
            feedbackType = 2;
        }else if(feedbackType=="商品反馈"){
            feedbackType = 3 ;
        }else if (feedbackType == "其他反馈") {
            feedbackType = 4;
        }else{
            feedbackType = ""
        }
        select(feedbackType);
    });

    //查看审核详情
    chakan = function chakan(feedbackId){
        $.ajax({
            type:"post",
            javaType:"json",
            data:{"feedbackId":feedbackId},
            url:"/Feedback/selectUserFeedBackById",
            success:function (data) {
                kan(data);
            }
        })
    };
    function kan(data){
        var obj;
        layer.open({
            type:2,
            content:"/feedback/feedback-see.html",
            area:['600px', '600px'],
            shade:0,
            btn:["确定"],
            yes:function(index){
                layer.close(index);
            },
            success:function (layero,index) {
                obj = layero.find('iframe').contents();
                //console.log(data);
                obj.find("#feedbackId").val(data.data.feedbackId);
                var feedbackType = data.data.feedbackType;
                if(feedbackType==2){
                    feedbackType =  "视频反馈";
                }else if(feedbackType==3){
                    feedbackType = "商品反馈";
                }else{
                    feedbackType = "其他反馈";
                }
                obj.find("#feedbackType").val(feedbackType);
                obj.find("#feedbackContent").val(data.data.feedbackContent);
                obj.find("#createDate").val(data.data.createDate);
                var feedbackStatus = data.data.feedbackStatus;
                if(feedbackStatus==2){
                    feedbackStatus =  '已提交';
                }else if(data.feedbackStatus==3){
                    feedbackStatus =  "待审核";
                }else if(data.feedbackStatus==4){
                    feedbackStatus = "审核通过";
                }else if(data.feedbackStatus==5){
                    feedbackStatus = "未提交";
                }else{
                    feedbackStatus = "审核驳回";
                }
                obj.find("#feedbackStatus").val(feedbackStatus);
                obj.find("#trueName").val(data.data.trueName);
                obj.find("#updateDate").val(data.data.updateDate);
            }
        })
    };

    //删除
    shanchu = function shanchu(feedbackId) {
        $.ajax({
            type:"post",
            dataType:"json",
            data:{"feedbackId":feedbackId},
            url:"/Feedback/delUserFeedBack",
            success:function (data) {
                if(data){
                    layer.msg("删除成功");
                    location.reload();
                }else{
                    layer.msg("删除失败");
                }
            }
        })
    };

    //顶部时间
    function getTime(date){
        var year = date.getFullYear(); //获取完整的年份(4位,1970-????)
        var month = date.getMonth()+1; //获取当前月份(0-11,0代表1月)
        var today = date.getDate(); //获取当前日(1-31)
        var hour = date.getHours(); //获取当前小时数(0-23)
        var minute = date.getMinutes(); //获取当前分钟数(0-59)
        var second = date.getSeconds(); //获取当前秒数(0-59)
        var nowTime;
        nowTime = year+'-'+fillZero(month)+'-'+fillZero(today)+' '+fillZero(hour)+':'+fillZero(minute)+':'+fillZero(second);
        return nowTime;
    };

    //时间的为零操作
    function fillZero(str){
        var realNum;
        if(str<10){
            realNum	= '0'+str;
        }else{
            realNum	= str;
        }
        return realNum;
    }
})